package cn.usian.controller;

import cn.usian.pojo.Emp;
import cn.usian.service.EmpService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping("findAll")
    public String findAll(Model model){
        List<Emp>list=empService.findAll();
        model.addAttribute("list",list);
        return "emp";
    }
    //添加
    @GetMapping("toAdd")
    public String toAdd(){
        return "add";
    }
    @PostMapping("add")
    public String add(Emp emp){
        empService.add(emp);
        return "redirect:findAll";
    }
    @GetMapping("delete")
    public String delete(Integer eid){
        empService.delete(eid);
        return "redirect:findAll";
    }
    @GetMapping("findByEid")
    public String findByEid(Model model,Integer eid){
        Emp emp=empService.findByEid(eid);
        model.addAttribute("emp",emp);
        return "update";
    }
    @PostMapping("update")
    public String update(Emp emp){
        empService.update(emp);
        return "redirect:findAll";
    }
}
